import type { Router } from 'vue-router';

// import { useAsyncRoutesStore } from '@/fierce/stores/async-routes';

export default (router: Router) => {
  router.afterEach(to => {
    const componentNames = to.matched
      .map(route => route.components?.default)
      .map(component => {
        if (component) {
          return component.name;
        }
        return null;
      })
      .filter(name => typeof name == 'string')
      .map(name => name as string);
    if (componentNames.length != 1) {
      //
    }

    // const asyncRoutesStore = useAsyncRoutesStore();
    // if (to.meta.keepAlive) {
    //   if (!asyncRoutesStore.hasCachedRoute(componentNames[0])) {
    //     asyncRoutesStore.addCachedRoute(componentNames[0]);
    //   }
    // } else {
    //   asyncRoutesStore.removeCacheRoute(componentNames[0]);
    // }
  });
};
